<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<div class="t_bar">
	<span class="color_red">*</span>任务分工信息（限填6条）
</div>
	<table  id="tblMileStones" cellpadding="0" class="table01" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
			<thead >
					<tr style="border:1px solid #B7D1E6">
						<th class="TblHead" align="center" rowspan="2" width="5%">选择</th>
						<th class="TblHead" align="center" rowspan="2" width="5%">序号</th>
						<th class="TblHead" align="center" rowspan="2" width="14%">具体实施单位<br/>（限200字）</th>
						<th class="TblHead" align="center" rowspan="2" width="19%">实施内容（限300字）</th>
						<th class="TblHead" align="center" rowspan="2" width="19%">进度安排（限300字）</th>
						<th class="TblHead" align="center" rowspan="2" width="19%">实施地点（限500字）</th> 
						<th class="TblHead" align="center" colspan="2" width="19%">经费使用情况（万元）</th> 
					</tr>
					<tr style="border:1px solid #B7D1E6">
						<th class="TblHead" align="center" width="9%" nowrap="nowrap">计划新增投资</th>
						<th class="TblHead" align="center" width="10%">专项经费</th>
					</tr>
			</thead>
			
			
			<tbody id="tab">
					<tr style="display:none">
						<td>
							<input type="radio" class="radiobutton" name="selMileStones" >
						</td>
						<td align="center"> 
							<span name="milestones|milestone[0]@seq_no" >[index]</span> 
						</td>
						<td align="center"> 
							<textarea name="milestones|milestone[0]|org_name" class="input_textarea required maxlength:200" label="具体实施单位" rows="8" style="width: 90%"></textarea>
							<input type="hidden" name="milestones|milestone[0]|org_name_hidden" />
						</td>
						<td align="center"> 
							<textarea name="milestones|milestone[0]|content" class="input_textarea required maxlength:300" label="实施内容"  rows="8" style="width: 90%"></textarea>
							<input type="hidden" name="milestones|milestone[0]|content_hidden" />
						</td> 
						<td  align="center">
							<textarea name="milestones|milestone[0]|schedule" class="input_textarea required maxlength:300" label="进度安排"  rows="8" style="width: 90%"></textarea>
							<input type="hidden" name="milestones|milestone[0]|schedule_hidden" />
						</td> 
						<td  align="center">
							<textarea name="milestones|milestone[0]|address" class="input_textarea required maxlength:500" label="实施地点"  rows="8" style="width: 90%"></textarea>
							<input type="hidden" name="milestones|milestone[0]|address_hidden" />
						</td> 
						<td align="center">
							<input type="text" id="add_[index]" name="milestones|milestone[0]|add" label="计划新增投资"  class="input_text required valueCompare:fund_[index]:add_[index]"  onfocus="InitInput.setNumber(this,7,4,2)" onchange="sumTotal('tblMileStones','add','add_total');"  style="width:80%;text-align: right;" />
						</td> 
					
						<td align="center">
							<input type="text" id="fund_[index]" name="milestones|milestone[0]|fund" label="专项经费" onfocus="InitInput.setNumber(this,7,4,2)" onchange="sumTotal('tblMileStones','fund','fund_total');" class=" input_text required" style="width:80%;text-align: right;"/>
						</td>
					</tr>
					
					
					<c:set value="0" var="index" scope="page"/>
					<x:forEach select="$xmlData/data/milestones/milestone" var="milestone">
					
					<c:choose>
						<c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
						<c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
					</c:choose>
					<tr >
						<td> 
							<input type="radio" class="radiobutton" name="selMileStones" >
						</td>
						<td align="center">
							<span   name="milestones/milestone[${flag}${index}]@seq_no" ><x:out select="$milestone/@seq_no"/></span> 
						</td>
						<td align="center"> 
							<textarea name="milestones/milestone[${flag}${index}]/org_name" class="input_textarea required maxlength:200" label="实施单位" rows="8" style="width: 90%"><x:out select="$milestone/org_name"/></textarea>
							<input type="hidden" name="milestones/milestone[${flag}${index}]/org_name_hidden" />
						</td>
						<td align="center"> 
							<textarea name="milestones/milestone[${flag}${index}]/content" class="input_textarea required maxlength:300" label="实施内容"  rows="8" style="width: 90%"><x:out select="$milestone/content"/></textarea>
							<input type="hidden" name="milestones/milestone[${flag}${index}]/content_hidden" />
						</td> 
						<td  align="center">
							<textarea name="milestones/milestone[${flag}${index}]/schedule" class="input_textarea required maxlength:300" label="进度安排"  rows="8" style="width: 90%"><x:out select="$milestone/schedule"/></textarea>
							<input type="hidden" name="milestones/milestone[${flag}${index}]/schedule_hidden" />
						</td> 
						<td  align="center">
							<textarea name="milestones/milestone[${flag}${index}]/address" class="input_textarea required maxlength:500" label="实施地点"  rows="8" style="width: 90%"><x:out select="$milestone/address"/></textarea>
							<input type="hidden" name="milestones/milestone[${flag}${index}]/address_hidden" />
						</td> 
						<td align="center">
							<input type="text" id="add_${index }" name="milestones/milestone[${flag}${index}]/add" value="<x:out select="$milestone/add"/>" label="计划新增投资"  class="input_text required valueCompare:fund_${index }:add_${index }"  onfocus="InitInput.setNumber(this,7,4,2)" onchange="sumTotal('tblMileStones','add','add_total');"  style="width:80%;text-align: right;" />
						</td> 
					
						<td align="center">
							<input type="text" id="fund_${index }" name="milestones/milestone[${flag}${index}]/fund" value="<x:out select="$milestone/fund"/>" label="专项经费" onfocus="InitInput.setNumber(this,7,4,2)" onchange="sumTotal('tblMileStones','fund','fund_total');" class=" input_text required" style="width:80%;text-align: right;"/>
						</td>
						 
					</tr>
					<c:set value="${index+1}" var="index" scope="page"/>
					</x:forEach>
					 
					</table>
					
				<table cellpadding="0" class="table01 t_css" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;" id="countOrgsTotal">
						<tr>
							<td align="center" width="81%">合计</td>
							<td width="9%" align="center">
								<input  id="add_total" style="width:80%;text-align: right;"  disabled="disabled " class="input_text gray valueEqual:add_total:source_add" label="合计-->计划新增投资合计" name="orgs/add_total" value='<x:out select="$xmlData/data/orgs/add_total"/>'>
							</td>
							<td width="10%" align="center"> 
								 <input  id="fund_total" style="width:80%;text-align: right;"  disabled="disabled" class=" input_text gray valueEqual:fund_total:source_apply" label="合计-->专项经费合计" name="orgs/fund_total" value='<x:out select="$xmlData/data/orgs/fund_total"/>'>
							</td>
						</tr>
				</table>
					<br>

					<table width="98%" align="center">
					<tr ><td>
					<input class="button" name="cmdAddbefore" type=button value="添加" onclick="if(checkTabLimit('tblMileStones',7,'任务分工信息最多只能填写6条')){addNewRow('tblMileStones');}try{top.resizeFrame();}catch(e){};">
					<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev('tblMileStones','selMileStones')">
					<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext('tblMileStones','selMileStones')">
					<input class="button" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow('tblMileStones','任务分工信息');sumTotal('tblMileStones','add','add_total');sumTotal('tblMileStones','fund','fund_total');">
					</td></tr>
	</table>

	
	
<script type="text/javascript">
		
		//对id="tableId"某表中，后缀名为sourceInputName所有求和，赋值给id="destInputId"的input
		function sumTotal(tableId,sourceInputName,destInputId){
			var sourceInputs = $("#"+tableId).find("input[name$='"+sourceInputName+"']");
			var count = 0;
			for ( var i = 0; i < sourceInputs.length; i++) {
			var fund = $(sourceInputs[i]).val();
			if (!$.isNumeric(fund))
			fund = "0";
			count = ((parseFloat(count)*10000 + parseFloat(fund)*10000)/10000).toFixed(4);
			}
			count = formatVal2(count);// 格式化金额
			$("#" +destInputId).val(count);
		} 
		

		$(function() {
			$("#tblMileStones tr:even").addClass("li_1");
			$("#tblMileStones tr:odd").addClass("li_2");
		});
		
		/**
		* 增加一行
		* @param tableId表格Id
		* @param radioId
		* @param nNewRowPosition
		* @param startRowIndex
		*/
		/* function addNewRowDeal(table){
			if (table.attr("id") == "tblMileStones")
			{
				var maxLinNum=table.find("tr").length-4;//获得行数，减去表头和隐藏行
				var lineNum=""+(maxLinNum+2);
				var addHtml=table.find("tr")[2].innerHTML;//获得隐藏行的html,查找第二行
				addHtml=addHtml.replace(/\[index\]/g,lineNum);
				lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
				if (lineNum.length==1)//如果是个位数，前面补0
				lineNum="0"+lineNum;
				addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
				addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
				table.append("<tr>"+addHtml+"</tr>");//将html增加到最后
					
			}
			else
			{
				var maxLinNum=table.find("tr").length-2;;//获得行数，减去表头和隐藏行
				var lineNum=""+(maxLinNum+1);
				var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
				addHtml=addHtml.replace(/\[index\]/g,lineNum);
				lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
				if (lineNum.length==1)//如果是个位数，前面补0
				lineNum="0"+lineNum;
				addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
				addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
				table.append("<tr>"+addHtml+"</tr>");//将html增加到最后
			} 
		} */
		
		/**
		* 上移行
		* @param tblId
		* @returns {Boolean}
		*/
	 	function movePrev(tblId,selName) {
			if (tblId == "tblMileStones")
			{		
				if (!selName)
					selName = "";
				if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
					scmWarn(irisNotes.prevWarn);
					return false;
				}
				if ($("#" + tblId + " tr").length <= 3)
					return false;
				var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked").parents("tr").first();// 取得被选中的行
				var trPrev = trChecked.prev(); // 取得上一行
				var index = trChecked.get(0).rowIndex; // 获得行号
				if (index <= 3) {// 已到第一行  不能上移
					scmWarn(irisNotes.tabelMoveWarn1);
					return false;
				}
				//trChecked.remove();
				trPrev.before(trChecked);
				trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
				refreshRowINdex(tblId);
			}
			else
			{
				 if (!selName)
					 selName = "";
					 if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
					 scmWarn(irisNotes.prevWarn);
					 return false;
					 }
					 if ($("#" + tblId + " tr").length <= 2)
					 return false;
					 var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
					 .parents("tr").first();// 取得被选中的行
					 var trPrev = trChecked.prev();// 取得上一行
					 var index = trChecked.get(0).rowIndex;// 获得行号
					 if (index <= 2) {// 如果是第一行
					 scmWarn(irisNotes.tabelMoveWarn1);
					 return false;
					 }
					 //trChecked.remove();
					 trPrev.before(trChecked);
					 trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
					 refreshRowINdex(tblId); 
			}
		}	 
		
		/**
		* 下移行
		* @param tblId
		* @returns {Boolean}
		*/
		 function moveNext(tblId,selName) {
			if (tblId == "tblMileStones")
			{
				if (!selName)
					selName = "";
				if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
					scmWarn(irisNotes.nextWarn);
					return false;
				}
				if ($("#" + tblId + " tr").length <= 3) {
					return false;
				}
				var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked").parents("tr").first();// 取得被选中的行
				var trNext = trChecked.next();
				var index = trChecked.get(0).rowIndex;// 获得行号
				if (index == $("#" + tblId + " tr").length - 1) {// 如果是第一行
					scmWarn(irisNotes.tabelMoveWarn2);
					return false;
				}
				//trChecked.remove();
				trNext.after(trChecked);
				trChecked.find(":radio[name*='" + selName + "']").attr("checked", "true");
				refreshRowINdex(tblId);
			}
			else
			{
				 if (!selName)
					 selName = "";
					 if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
					 scmWarn(irisNotes.nextWarn);
					 return false;
					 }
					 if ($("#" + tblId + " tr").length <= 2) {
					 return false;
					 }
					 var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
					 .parents("tr").first();// 取得被选中的行
					 var trNext = trChecked.next();
					 var index = trChecked.get(0).rowIndex;// 获得行号
					 if (index == $("#" + tblId + " tr").length - 1) {// 如果是第一行
					 scmWarn(irisNotes.tabelMoveWarn2);
					 return false;
					 }
					 //trChecked.remove();
					 trNext.after(trChecked);
					 trChecked.find(":radio[name*='" + selName + "']").attr("checked", "true");
					 refreshRowINdex(tblId); 
			}
		}  
		
		
		
		/**
		* 重新计算行号
		* @param tblId
		*/
		
			function refreshRowINdex(tblId) {
				if (tblId == "tblMileStones")
				{
					//重新计算行号
					$("#" + tblId + " tr").each(
							function() {
								var seq = $(this).get(0).rowIndex;//获得行数
								if (seq > 2) {//如果有行 显示时display行不计入类，故只减1
									seq = seq - 2;
									var seq_no = $(this).find("[name$='seq_no']");
									if (seq_no.is("span"))
										seq_no.html(seq);
									else
										seq_no.val(seq);
									
									seq = "" + (seq - 1);
									if (seq.length == 1)
										seq = "0" + seq;
									//替换相应的name参数的seq
									$(this).find("input,span,textarea,select").each(
											function() {
												var name = $(this).attr("name");
												if (name != null && name != "") {
													name = name.replace(/\[\d*\]/g, "["
															+ seq + "]");
													$(this).attr("name", name);
												}
												var id = $(this).attr("id");
												if (id != null && id != "") {
													id = id.replace(/\[\d*\]/g, "["
															+ seq + "]");
													$(this).attr("id", id);
												}
												var className = $(this).attr("class");
												if (className != null
														&& className != "") {
													className = className
															.replace(/\[\d*\]/g, "["
																	+ seq + "]");
													$(this).attr("class", className);
												}
											});
								}
							});
				}
				else
				{
					$("#"+tblId+" tr").each(function(){
						var seq=$(this).get(0).rowIndex;//获得行数
						if(seq>1){//如果有行 显示时display行不计入类，故只减1
						seq=seq-1;
						var seq_no=$(this).find("[name$='seq_no']");
						if(seq_no.is("span"))
						seq_no.html(seq);
						else
						seq_no.val(seq);
						seq=""+(seq-1);
						if(seq.length==1)
						seq="0"+seq;
						//替换相应的name参数的seq
						$(this).find("input,span,textarea,select").each(function(){
						var name=$(this).attr("name");
						if(name!=null&&name!=""){
						name=name.replace(/\[\d*\]/g,"["+seq+"]");
						$(this).attr("name",name);
						}
						var id=$(this).attr("id");
						if(id!=null&&id!=""){
						id=id.replace(/\[\d*\]/g,"["+seq+"]");
						$(this).attr("id",id);
						}
						var className=$(this).attr("class");
						if(className!=null&&className!=""){
						className=className.replace(/\[\d*\]/g,"["+seq+"]");
						$(this).attr("class",className);
						}
						});
						}
						}
						); 
				}
			}
</script>